package com.tengju.user.infrastructure.repository.sign;

import com.tengju.user.domain.model.archive.sign.SignFromEnum;
import com.tengju.user.domain.model.archive.sign.SignId;
import com.tengju.user.domain.model.archive.sign.SignRecord;
import com.tengju.user.domain.model.archive.sign.SignRecordRepository;
import com.tengju.user.infrastructure.persistence.mybatis.dataobject.SignRecordDO;
import com.tengju.user.infrastructure.persistence.mybatis.mapper.dealer.generate.SignRecordDOMapper;
import com.tengju.user.infrastructure.repository.convert.SignRecordConvert;
import org.springframework.stereotype.Repository;

@Repository
public class SignRecordRepositoryImpl implements SignRecordRepository {

    private final SignRecordDOMapper signRecordDOMapper;

    public SignRecordRepositoryImpl(SignRecordDOMapper signRecordDOMapper) {
        this.signRecordDOMapper = signRecordDOMapper;
    }

    public int insertSelective(SignRecord signRecord) {
        SignRecordDO record = SignRecordConvert.convert(signRecord);
        return signRecordDOMapper.insertSelective(record);
    }

    @Override
    public SignRecord findOne(SignId signId, SignFromEnum signForm) {
        SignRecordDO record = signRecordDOMapper.getFirst(signId.getValue(), signForm.getCode(), 0);
        return SignRecordConvert.convert(record);
    }

    @Override
    public int endServiceSignRecord(SignId signId) {
        return signRecordDOMapper.endServiceSignRecord(signId.getValue());
    }

    @Override
    public SignRecord findOrderBy(SignId signId) {
        SignRecordDO record = signRecordDOMapper.getOrderBy(signId.getValue(),
                SignFromEnum.SERVICE_PROVIDER.getCode());
        return SignRecordConvert.convert(record);
    }


}
